﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace park.ListSensor
{
    public partial class ListSensorList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string method = Request.Params["method"];
                if (!string.IsNullOrEmpty(method))
                {
                    switch (method)
                    {
                        case "ListSensor":
                            PrintResult();
                            break;
                        case "DeleteSensor":
                            PrintDelResult();
                            break;
                        default:
                            Response.End();
                            break;
                    }
                    
                }
            }
        }

        private void PrintDelResult()
        {

            #region 正式代码
            string sensorId = Request.Params["sensorId"];

            cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();

            bool result = sl.DeleteSensor(sensorId);

            if (result)
            {
                Response.Write("{\"ListSensor\":\"删除成功\"}");
                Response.End();
            }
            else
            {
                Response.Write("{\"ListSensor\":\"删除失败\"}");
                Response.End();
            }
            #endregion

            #region 测试代码
            //string sensorId = Request.Params["sensorId"];

            //bool result =true;

            //if (result)
            //{
            //    Response.Write("{\"ListSensor\":\"删除成功\"}");
            //    Response.End();
            //}
            //else
            //{
            //    Response.Write("{\"ListSensor\":\"删除失败\"}");
            //    Response.End();
            //}
            #endregion


        }

        private void PrintResult()
        {

            #region 正式代码
            string meteredNo = Request.Params["meteredNo"];
            string parkingNo = Request.Params["parkingNo"];
            string name = Request.Params["name"];
            string longitude = Request.Params["longitude"];
            string latitude = Request.Params["latitude"];
            string streetCode = Request.Params["streetCode"];
            string inducedScreenNo = Request.Params["inducedScreenNo"];

            int page = int.Parse(Request.Params["page"]);
            int size = int.Parse(Request.Params["size"]);

            cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();

            string json = sl.ListSensor(meteredNo, parkingNo, name, longitude, latitude, streetCode, inducedScreenNo, page, size);

            Response.Write(json);
            Response.End();
            #endregion

            #region 测试代码
        //    int total = 100;
        //    string result = ""
        //        + "[{"
        //+ "\"ID\": 1,"
        //+ "\"No\": \"TSN4515\","
        //+ "\"ParkingSpaceNo\": \"T-S-103\","
        //+ "\"Model\": \"SK894610\","
        //+ "\"Manufacturer\": \"武汉通讯公司\","
        //+ "\"Connection\": \"18627870000\","
        //+ "\"InstallTime\": \"2012-12-05\","
        //+ "\"Description\":\"配件说明...\","
        //+ "\"Repeaters\": \"AS56952\""
        //        + "},"
        //        + "{"
        //+ "\"ID\": 2,"
        //+ "\"No\": \"TSN4515\","
        //+ "\"ParkingSpaceNo\": \"T-S-103\","
        //+ "\"Model\": \"SK894610\","
        //+ "\"Manufacturer\": \"武汉通讯公司\","
        //+ "\"Connection\": \"18627870000\","
        //+ "\"InstallTime\": \"2012-12-05\","
        //+ "\"Description\":\"配件说明...\","
        //+ "\"Repeaters\": \"AS56952\""
        //        + "}]";
        //    string json = string.Empty;

        //    json = "{\"ListSensor\":" + result + ",\"RowsCount\":" + total + "}";

        //    Response.Write(json);
        //    Response.End();
            //测试代码---------------------------
            #endregion


        }
    }
}